<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>设备状态</title>
	<jsp:include page="/common/header-common.jsp"></jsp:include>
	<script type="text/javascript">
	function getAjax() {
		$.ajax({
				type: "POST",
				url:'userDevice!ajax.action',
				dataType:"json",
				success:function(result){
					if(result.tip != "") {
						$("<div class='return_tip'>" + result.tip + "</div>").insertAfter(".rss_title");
						window.clearInterval(id);
					} else {
						$("#tableid").html('');
						$.each(result.beans, function(index){
							var htmlstring = "<tr align='left'><td class='rss_label'><span>车号：</span><br />" 
								+ "<span>状态：</span><br /><span>最后加油时间：</span><br /><span>最后信号强度：</span></td><td class='rss_field'><span>" 
								+ result.beans[index].carnum + "</span><br /><span>" + result.beans[index].reason 
								+ "</span><br /><span>" + result.beans[index].oiltime + "</span><br /><span>" 
								+ result.beans[index].signstatus + "</span></td>"
								+ "<td class='rss_field' height='60' width='200'>";
							if(result.beans[index].reason == "当前设备已欠费，无法查询相关信息" 
								|| result.beans[index].reason == "未有当前设备状态信息") {
								htmlstring += result.beans[index].reason;
							} else {
								if(result.beans[index].reason == "状态正常") {
									htmlstring += "<img src='../images/green.jpg' height='60' width='60' align='left' />";
								} else {
									htmlstring += "<img src='../images/red.jpg' height='60' width='60' align='left' />";
								}
							}
							htmlstring += "</td></tr>";
							$(htmlstring).appendTo("#tableid");
						});
					}
				},
				error:function(){
					alert('与服务器通信失败，请稍候再试');
					window.clearInterval(id);
				}
			});
	}
	var id = window.setInterval(getAjax,2000); 
	</script>
</head>

	<body id="userdevice">
		<div id="wrapper">
			<jsp:include page="/common/header.jsp"></jsp:include>
			<jsp:include page="navication.jsp"></jsp:include>
			<div id="rss_content">
				<div class="rss_title">设备状态</div>
				<s:if test="message != null">
					<div class="return_tip">
						<s:property value="message" />
					</div>
				</s:if>
				<s:iterator value="beans" id="bean">
					<table id="tableid">
						<tr align="left">
							<td class="rss_label">
								<span>车号：</span><br />
								<span>状态：</span><br />
								<span>最后加油时间：</span><br />
								<span>最近信号强度：</span>
							</td>
							<td class="rss_field">
								<span><s:property value="#bean.sdevice.carnum" /></span><br />
								<span>
									<s:if test="#bean.flag == false">
										当前设备已欠费，无法查询相关信息
									</s:if>
									<s:elseif test="#bean.sinfo == null">
										未有当前设备状态信息
									</s:elseif>
									<s:elseif test="#bean.sinfo.reason == 1 || #bean.sinfo.reason == 2 || #bean.sinfo.reason == 3 ">
										<s:property value="#bean.sinfo.chReason" />
									</s:elseif>
									<s:else>状态正常</s:else>
								</span><br />
								<span>
									<s:if test="#bean.flag == false">
										当前设备已欠费，无法查询相关信息
									</s:if>
									<s:elseif test="#bean.srefuel == null">
										未有当前设备加油信息
									</s:elseif>
									<s:else>
										<s:if test="#bean.srefuel.starttime != null && #bean.srefuel.endtime == null">
											正在加油中
										</s:if>
										<s:else>
											<s:date name="#bean.srefuel.starttime" format="yy-MM-dd HH:mm:ss"/> -- <s:date name="#bean.srefuel.endtime" format="yy-MM-dd HH:mm:ss"/>
										</s:else>
										
									</s:else>
								</span><br />
								<span>
									<s:if test="#bean.flag == false">
										当前设备已欠费，无法查询相关信息
									</s:if>
									<s:elseif test="#bean.srefuel == null">
										未有当前设备状态信息
									</s:elseif>
									<s:else>
										<s:property value="#bean.sinfo.signalstatus" />
									</s:else>
								</span>
							</td>
							<td class="rss_field" height="60" width="200">
									<s:if test="#bean.flag == false">
										当前设备已欠费，无法查询相关信息
									</s:if>
									<s:elseif test="#bean.sinfo == null">
										未有当前设备状态信息
									</s:elseif>
									<s:elseif test="#bean.sinfo.reason == 1 || #bean.sinfo.reason == 2 || #bean.sinfo.reason == 3 ">
										<img src="../images/red.jpg" height="60" width="60" align="left" />
									</s:elseif>
									<s:else><img src="../images/green.jpg" height="60" width="60" align="left"/></s:else>
								
							</td>
						</tr>
					</table>
				</s:iterator>
			</div>
			<div style="clear: both;"></div>
			<div style="height: 40px;" ></div>
			<s:include value="/common/footer.jsp"></s:include>
		</div>
	</body>
</html>